package com.yuxinmuyu.sports_management.controller.publicController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuxinmuyu.sports_management.bean.entiy.SportsProject;
import com.yuxinmuyu.sports_management.bean.request.*;
import com.yuxinmuyu.sports_management.bean.response.*;
import com.yuxinmuyu.sports_management.exception.R;
import com.yuxinmuyu.sports_management.service.SportsProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/sportsProject")
@Api(value ="运动项目",tags = {"运动会项目"})
public class SportsProjectController {
    @Resource
    SportsProjectService sportsProjectService;
    @ApiOperation("获取运动会项目分页列表")
    @PostMapping("/getPage")
    public R<Page<SportsProject>>getPage(@RequestBody @Validated GetSportsProjectRequest request){
        return R.success(sportsProjectService.getPage(request));
    }
    @ApiOperation("获取学期下拉框")
    @PostMapping("/getYearSelectList")
    public R<List<YearTermResponse>>getSelectList(){
        List<YearTermResponse>list=sportsProjectService.getSelectList();
        list.add(0,new YearTermResponse(null,"全部"));
        return R.success(list);
    }

    @ApiOperation("获取院系下拉框")
    @PostMapping("/getDeptSelectList")
    public R<List<DeptResponse>>getDeptSelectList(){
        List<DeptResponse>list=sportsProjectService.getDept();
        list.add(0,new DeptResponse(null,"全部"));
        return R.success(list);
    }

    @ApiOperation("获取专业下拉框")
    @PostMapping("/getMajorSelectList")
    public R<List<MajorResponse>>getMajorSelectList(@RequestBody @Validated GetDeptNameRequest request){
        List<MajorResponse>list=sportsProjectService.getMajor(request);
        list.add(0,new MajorResponse(null,"全部"));
        return R.success(list);
    }

    @ApiOperation("获取班级下拉框")
    @PostMapping("/getClassSelectList")
    public R<List<ClassResponse>>getClassSelectList(@RequestBody @Validated GetClassListRequest request){
        List<ClassResponse>list=sportsProjectService.getSClass(request);
        list.add(0,new ClassResponse(null,"全部"));
        return R.success(list);
    }
    @ApiOperation("根据ID获取项目与信息")
    @PostMapping("/getInfoByID")
    public R<GetSportsInfoResponse>getInfoByID(@RequestBody @Validated GetSportsInfoRequest request){
        return R.success(sportsProjectService.getInfoByID(request));
    }
    @ApiOperation("根据ID删除项目与信息")
    @PostMapping("/adm/deleteInfoByID")
    public R<?>deleteInfoByID(@RequestBody @Validated GetSportsInfoRequest request){
        sportsProjectService.deleteInfoByID(request);
        return R.success("删除成功！");
    }
    @ApiOperation("根据ID修改项目信息")
    @PostMapping("/adm/updateInfoByID")
    public R<?>updateByID(@RequestBody @Validated UpdateSportsInfoRequest request){
        sportsProjectService.updateByID(request);
        return R.success("修改成功！");
    }
    @ApiOperation("导出项目信息")
    @PostMapping("/export")
    public void export(@RequestBody @Validated GetSportsProjectRequest request, @ApiIgnore HttpServletResponse response) throws IOException {
        sportsProjectService.export(request,response);
    }
}
